<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 1.正则方法：test返还true或false
      //   var reg = /\d+/;
      //   var str = "123o";
      //   console.log(reg.test(str));

      //   2.exec可以获取匹配到的值

      //   var reg = /\d+/g;
      //   var str = "fas123sdjdia838sd21321";
      //   console.log(reg.exec(str));
      //   console.log(reg.exec(str));
      //   console.log(reg.exec(str));
      // 3.字符串方法split()字符串变成数组
      //   var reg = /\d+/;
      //   var str = "kdj123654scsa11k";
      //   var arr = str.split(reg);
      //   console.log(arr);
      //   4.search搜索
      //   var reg = /\d+/;
      //   var str = "d1a1ha";
      //   console.log(str.search(reg));
      //   4.replace替换
      var str = "fasdsm1sadsm2dfsm55";
      var reg = /sm\d+/gi;

      var res = str.replace(reg, function (arg) {
        console.log(arg);
        var resstr = "";
        for (var i = 0; i < arg.length; i++) {
          resstr += "*";
        }
        return resstr;
      });
      console.log(res);
    </script>
  </body>
</html>
